

<div class="layui-form" lay-filter="layuiadmin-form-role" id="form">
	<div class="form-cont">
		<div class="layui-form-item verify">
		  <label class="layui-form-label">公告标题</label>
		  <div class="layui-input-block">
			  <input type="text" autocomplete="off" v-model="detail.title" verify='requirel5' placeholder="请输入公告标题" class="layui-input">
			  <span class="hint">请输入公告标题</span>
			</div>
		</div>
		<div class="layui-form-item">
		  <label class="layui-form-label">是否发布</label>
		  <div class="layui-input-block">
		      <div class="layui-unselect layui-form-switch" :class="{'layui-form-onswitch':detail.status==1}" lay-skin="_switch" @click="radioF()"><em>{{detail.status==1?'是':'否'}}</em><i></i></div>
		  </div>
		</div>
		<div class="layui-form-item">
		  <label class="layui-form-label">公告详情</label>
		  <div class="layui-input-block">
		      <textarea id="edit" style="display: none;"></textarea>
		  </div>
		</div>
	</div>
  <div class="form-btn" v-if="type!=3">
      <input type="button" value="保存" class="layui-btn">
  </div>
</div>
<style type="text/css">
	.layui-layedit{
		
	}
</style>
<script>
	var forms=new Vue({
			el:'#form',
			data:{
				role:[],
					type:layui.admin.objData.type,
					detail:{
						status:1
					},
					old_detail:{}
			},
			mounted() {
					//初始化
				var _this=this;
				if(this.type!=1) this.detail=layui.admin.objData.detail,this.old_detail=JSON.stringify(layui.admin.objData.detail);

				layui.$('#edit').html(this.detail.details);
					layui.use('layedit', function(){
					  var layedit=layui.layedit,$=layui.$;
					  /* layedit.set({
							  uploadImage: {
								  url: layui.conf.ajaxUrl+'login/upload_img'
								  ,type: 'post'
							  }
					  }); */
					  var index=layedit.build('edit',{
						  tool: ['strong' //加粗
						  ,'italic' //斜体
						  ,'underline' //下划线
						  ,'del' //删除线
						  
						  ,'|' //分割线
						  
						  ,'left' //左对齐
						  ,'center' //居中对齐
						  ,'right'
							  ,'link' //超链接
							  ,'unlink' //清除链接
							  ,'face' //表情
							  ,'image' //插入图片
							 ],
						 height: 300
					  });
					  $('.form-btn input').click(function(){
						  var data=layedit.getContent(index);
						  _this.submit(data)
					  });
					});
			},
			methods:{
				radioF(){//radio选择
					this.detail.status==1?this.detail.status=2:this.detail.status=1;
				},
				submit(data){
					if(layui.admin.form('#form')){
						if(!data){
							return layui.admin.ahint(2,'公告详情必填');
						}
						this.detail.details=data;

						if(this.type==2){   //编辑
							var data=layui.admin.filter(this.detail,JSON.parse(this.old_detail),'notice_id');
							if(data){
								layui.admin.formapi('notify/update',data);
							}
						}else{  //添加
							layui.admin.formapi('notify/add',this.detail);
						}
					}
				}
			}
		})
</script>
